package com.example.zsf.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.zsf.R;
import com.example.zsf.base.ZSFBaseActivity;
import com.example.zsf.model.CollectRecordModel;
import com.example.zsf.view.CollectedInfoDialog;
import com.example.zsf.view.CollectedSuccessDialog;
import com.example.zsf.view.EnterInfomationDialog;

import java.util.List;

public class CollectRecordListAdapter extends BaseQuickAdapter<CollectRecordModel.CollectRecordListModel, BaseViewHolder> {
    private ZSFBaseActivity context;

    public CollectRecordListAdapter(ZSFBaseActivity context, int layoutResId, List<CollectRecordModel.CollectRecordListModel> data) {
        super(layoutResId, data);
        this.context = context;
    }


    @Override
    protected void convert(BaseViewHolder baseViewHolder, CollectRecordModel.CollectRecordListModel collectRecordListModel) {
        Glide.with(context).load(collectRecordListModel.getAds_img()).into((ImageView) baseViewHolder.getView(R.id.content_im));

        baseViewHolder.setText(R.id.textView22, collectRecordListModel.getAds_name());
        baseViewHolder.setText(R.id.textView28, collectRecordListModel.getRcv_time());
        baseViewHolder.setText(R.id.textView26, collectRecordListModel.getRcv_open_name());


        TextView view = baseViewHolder.getView(R.id.textView29);
        int status = Integer.parseInt(collectRecordListModel.getRcv_status());
        switch (status) {
            case 0:
                view.setText("待充值");
                view.setBackground(context.getResources().getDrawable(R.drawable.bg_title_orange));
                break;
            case 1:
                view.setText("已充值");
                view.setBackground(context.getResources().getDrawable(R.drawable.bg_title_green));
                break;
            case 2:
                view.setText("异常");
                view.setBackground(context.getResources().getDrawable(R.drawable.bg_mark_red));
                break;
            case 3:
                view.setText("已退回");
                view.setBackground(context.getResources().getDrawable(R.drawable.bg_mark_red));
                break;
            case 4:
                view.setText("待填写");
                view.setBackground(context.getResources().getDrawable(R.drawable.bg_title_green));
                break;
        }

        baseViewHolder.getView(R.id.info_bt).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (status == 4) {
                    //待填写
                    EnterInfomationDialog enterInfomationDialog = new EnterInfomationDialog(context, null, collectRecordListModel, new EnterInfomationDialog.EnterInfoListener() {
                        @Override
                        public void confirmCallBack() {
                            if (getOnItemChildClickListener() != null) {
                                getOnItemChildClickListener().onItemChildClick(CollectRecordListAdapter.this, view, baseViewHolder.getAdapterPosition());
                            }
                        }
                    });
                    enterInfomationDialog.show();
                } else {
                    CollectedInfoDialog collectedInfoDialog = new CollectedInfoDialog(context,null,collectRecordListModel);
                    collectedInfoDialog.show();
                }
            }
        });
    }
}
